import GameConst from "../const/GameConst"
import { BaseLogic } from "./BaseLogic"
import { BaseState } from "./BaseState"

export class BaseComponents<T extends BaseState,L extends BaseLogic<T>> extends cc.Component {

    //逻辑层
    protected logic:L
    //数据层
    protected state:T

    public init(logic:L,state:T) {
        this.logic = logic
        this.state = state
    }

    public onBtnClick(e,type) {
        this.logic[type](e,type)
    }

    protected onEnable(): void {
        cc.game.once(GameConst.Event.SCENE_ENABLE,this.logic.init)
    }


    protected onDisable(): void {
        this.logic.dispose()
    }


}